#!/usr/bin/python
'''
Created by Colin Gillespie <c.gillespie@ncl.ac.uk>
Last Changed on: $Date: 2008-03-13 19:50:58 +0000 (Thu, 13 Mar 2008) $

A Maple format file
 
'''

__revision__ = '$Revision: 73 $'

def getHeader():
    header = '''<?xml version="1.0" encoding="UTF-8"?>
<Worksheet><Version major="6" minor="1"/>
<View-Properties>
    <Zoom percentage="100"/>
</View-Properties>

<Styles>
    <Layout alignment="left" bullet="none" firstindent="0.0" leftmargin="0.0" linebreak="space" linespacing="0.0" name="Normal" rightmargin="0.0" spaceabove="0.0" spacebelow="0.0"/>
    <Font background="[0,0,0]" bold="true" executable="true" family="Monospaced" foreground="[255,0,0]" name="Maple Input" opaque="false" size="12"/>
</Styles>
'''
    return header

def getFooter():
    return '</Worksheet>'

    
def getSectionHeader(expression=''):
    value = '''<Section>
    <Title>
    <Text-field layout="Heading 1" '<Section>
    <Title>
    <Text-field layout="Heading 1" style="Heading 1">%s</Text-field>
    </Title>'''% expression
    return value
    
def getSectionFooter():    
    return '</Section>'

def wrapExpression(expression):
    '''Wraps a string as maple code'''
    part = '''<Group>
    <Input>
        <Text-field layout="Normal" prompt="&gt; " style="Maple Input">%s</Text-field>
    </Input>
</Group>
    ''' % expression
    return part

def getBanner(expression):
    '''Produces a banner comment'''
    banner = "".join(40*['#']) + '\n'
    no_hash = (40 - len(expression))/2
    banner += "".join(no_hash*['#']) + expression + "".join(no_hash*['#']) 
    banner += '\n'
    banner += "".join(40*['#']) + '\n'
    return banner

if __name__ == '__main__':
    print getHeader()
    print getFooter()
    print wrapExpression('HI')
    print getBanner('Test1')
